#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

inline void gi(int &x)
{
	x=0;char ch=getchar();
	while(ch<'0'||'9'<ch) ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
}

const int N=2e6+9;
int n,b[N],c;
vector<int> a[N];
int lsh[N],lm=0;
int pos[N],lm2=0;
vector<int> cf0[N];
int cnt[N];

ll ans=0;
vector<int> ans_pos;

int tmp[N];
signed main()
{
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	gi(n);
	for(int i=1;i<=n;i++)
	{
		int k;
		gi(k);
		for(int j=1;j<=k;j++) gi(tmp[j]);
		sort(tmp+1,tmp+k+1);k=unique(tmp+1,tmp+k+1)-tmp-1;
		a[i].resize(k+1);
		for(int j=1;j<=k;j++) lsh[++lm]=a[i][j]=tmp[j];
		for(int j=1;j<k;j++) pos[++lm2]=a[i][j+1]-a[i][j]+1;
	}
	gi(c);
	for(int i=1;i<=n;i++) gi(b[i]);
	pos[++lm2]=1;
	sort(lsh+1,lsh+lm+1),lm=unique(lsh+1,lsh+lm+1)-lsh-1;
	sort(pos+1,pos+lm2+1),lm2=unique(pos+1,pos+lm2+1)-pos-1;
	
	for(int i=1;i<=n;i++)
	for(int j=1;j<a[i].size();j++)
	cnt[lower_bound(lsh+1,lsh+lm+1,a[i][j])-lsh]++;
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j+1<a[i].size();j++)
		{
			int p1=lower_bound(pos+1,pos+lm2+1,a[i][j+1]-a[i][j]+1)-pos;
			int p2=lower_bound(lsh+1,lsh+lm+1,a[i][j+1])-lsh;
			cf0[p1].push_back(p2);
		}
	}
	
	ll ss=0;
	int pcnt=0;
	for(int i=1;i<=lm;i++) ss+=1ll*b[cnt[i]]*cnt[i];
	for(int i=1;i<=n;i++) pcnt+=(a[i].size()-1);
	ss+=1ll*pcnt*c;
	
	ans=ss;ans_pos.push_back(1);
	for(int t=2;t<=lm2;t++)
	{
		ss+=1ll*pcnt*(pos[t]-pos[t-1])*c;
		ss-=1ll*cf0[t].size()*c;
		pcnt-=cf0[t].size();
		for(int p:cf0[t]) ss-=1ll*b[cnt[p]]*cnt[p],cnt[p]--,ss+=1ll*b[cnt[p]]*cnt[p];
		if(ss<ans) ans=ss,ans_pos.clear(),ans_pos.push_back(pos[t]);
		else if(ans==ss) ans_pos.push_back(pos[t]);
	}
	
	printf("%lld %d\n",ans,ans_pos.size());
	for(int p:ans_pos) printf("%d ",p);
}
